<template>
  <div class="photolist">
    <van-tabs animated>
      <van-tab
        v-for="cate in cates"
        :key="cate.id"
      >
        <template #title>
          <div @click="getImages(cate.id)">
            {{ cate.title }}
          </div>
        </template>
        <div
          class="imgs-box"
          v-if="images.length > 0"
        >
          <img
            v-for="item in images"
            :key="item.id"
            v-lazy="item.img_url"
            alt=""
            @click="goDetail('/home/photoinfo', item.id)"
          />
        </div>
        <div v-else>暂无数据</div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
// import mixins from '@/mixins';
export default {
  // mixins: [mixins],
  data() {
    return {
      cates: [],
      images: [],
    };
  },
  created() {
    this.getImageCategory();
    this.getImages(0);
  },
  methods: {
    async getImageCategory() {
      const res = await this.$http.getImageCategory();
      res.data.message.unshift({
        id: 0,
        title: '全部',
      });
      this.cates = res.data.message;
    },
    async getImages(id) {
      console.log(id);
      const res = await this.$http.getImages(id);
      this.images = res.data.message;
    },
    // goDetail(id) {
    //   this.$router.push('/home/photoinfo/' + id);
    // },
  },
};
</script>
<style lang="scss" scoped>
.photolist {
  .imgs-box {
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
